﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Library.Web.Infrastructure
{
	public class PagedList<T> : PagedListBase
	{
		public const int PageSize = 5;

		public IEnumerable<T> Result { get; private set; }

		#region ctor
		public PagedList(IQueryable<T> entities, int pageIndex)
		{
			if (entities == null)
			{
				throw new ArgumentNullException();
			}

			if (pageIndex > 1)
			{
				pageIndex -= 1;
			}
			else
			{
				pageIndex = 0;
			}

			TotalCount = entities.Count();
			TotalPages = (int)Math.Ceiling((double)TotalCount / (double)PageSize);
			CurrentPage = pageIndex;

			Result = entities
				.Skip(CurrentPage * PageSize)
				.Take(PageSize)
				.ToList();
		} 
		#endregion
	}

	
}